# beihang_models.py
"""
北航航线规划接口数据模型
基于北航提供的接口文档定义
"""
from typing import List, Dict, Any, Optional
from pydantic import BaseModel, Field
from datetime import datetime

class RoutePointRequest(BaseModel):
    """航点请求"""
    longitude: float = Field(..., description="经度")
    latitude: float = Field(..., description="纬度")
    altitude: float = Field(..., description="高度")

class DeviceInfo(BaseModel):
    """设备信息"""
    deviceId: int = Field(..., description="设备ID")
    deviceTag: str = Field(..., description="设备标识")

class SensitiveArea(BaseModel):
    """敏感区域"""
    type: str = Field(..., description="敏感区域类型")
    geom: str = Field(..., description="WKT格式的几何数据")

class EnvironmentalInfo(BaseModel):
    """环境信息"""
    obstacles: List[str] = Field(default=[], description="障碍物WKT列表")
    waterways: List[str] = Field(default=[], description="河道WKT列表")
    roads: List[str] = Field(default=[], description="道路WKT列表")
    noFlyZones: List[str] = Field(default=[], description="禁飞区WKT列表")
    sensitiveAreas: List[SensitiveArea] = Field(default=[], description="敏感区域列表")

class BeihangRoutePlanRequest(BaseModel):
    """北航航线规划请求"""
    batchPlanningQuantity: int = Field(1, description="批量规划数量")
    takeoffIntervalTime: Optional[int] = Field(None, description="起飞间隔时间(分钟)")
    deviceInfos: List[DeviceInfo] = Field(..., description="设备信息集合")
    deviceModel: str = Field(..., description="设备型号")
    outBizCode: str = Field(..., description="业务唯一标识")
    routeType: str = Field(..., description="航线类型(point点航线，area面航线)")
    startPoint: Optional[RoutePointRequest] = Field(None, description="起飞点")
    endPoint: Optional[RoutePointRequest] = Field(None, description="降落点")
    wayPoints: List[RoutePointRequest] = Field(default=[], description="途径点")
    startTime: Optional[datetime] = Field(None, description="起飞时间")
    plannedRouteInfos: List[Dict[str, Any]] = Field(default=[], description="已规划航线信息")
    environmentalInfo: EnvironmentalInfo = Field(..., description="环境信息")
    extraInfo: Dict[str, Any] = Field(default={}, description="拓展信息")

class RoutePointResponse(BaseModel):
    """航点响应"""
    longitude: float = Field(..., description="经度")
    latitude: float = Field(..., description="纬度")
    altitude: float = Field(..., description="高度")
    speed: float = Field(..., description="速度")
    timestamp: int = Field(..., description="时间戳")
    pitch: float = Field(0.0, description="俯仰角")
    roll: float = Field(0.0, description="翻滚角")
    yaw: float = Field(0.0, description="偏航角")
    xVelocity: float = Field(0.0, description="X轴速度分量")
    yVelocity: float = Field(0.0, description="Y轴速度分量")
    zVelocity: float = Field(0.0, description="Z轴速度分量")

class RouteInfoResponse(BaseModel):
    """航线信息响应"""
    outBizCode: str = Field(..., description="业务唯一标识")
    routePoints: List[RoutePointResponse] = Field(..., description="航线点位")
    startTime: datetime = Field(..., description="开始时间")
    endTime: datetime = Field(..., description="结束时间")
    maxAlt: int = Field(..., description="高度海拔上限(m)")
    minAlt: int = Field(..., description="高度海拔下限(m)")
    width: int = Field(..., description="宽度(m)")
    length: float = Field(..., description="长度(m)")

class BeihangRoutePlanResponse(BaseModel):
    """北航航线规划响应"""
    routeInfos: List[RouteInfoResponse] = Field(..., description="航线信息列表")
    extraInfo: Dict[str, Any] = Field(..., description="拓展信息")

class DeviceReportData(BaseModel):
    """设备上报数据"""
    deviceTag: str = Field(..., description="设备标识")
    reportTime: int = Field(..., description="上报时间戳")
    attr: Dict[str, Any] = Field(..., description="属性数据")